﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace AppFabricAdministrator
{
    public partial class RemoveCache : UserControl
    {
        private static string RemoveCacheCmd = @"Remove-Cache -CacheName {0}";
        
        NamedCaches ncs;
        public RemoveCache()
        {
            InitializeComponent();
            ncs=NamedCaches.GetCurrentNamedCaches(false);
            ncs.Dock=DockStyle.Fill;
            this.scRC.Panel1.Controls.Clear();
            this.scRC.Panel1.Controls.Add(ncs);
        }

        private void btnRemoveCache_Click(object sender, EventArgs e)
        {
            string selectedCache = ncs.SelectedNamedCache;
            if(!string.IsNullOrEmpty(selectedCache))
            {
                var cmd=string.Format(RemoveCacheCmd,selectedCache);
                var scriptSuccessMsg=string.Format("NamedCache {0} Removed successfully",selectedCache);
                AppfabricAdministrator.Current.RunScript(cmd, scriptSuccessMsg);
                ncs.UpdateNamedCaches();
            }
        }

        private void btnClearCache_Click(object sender, EventArgs e)
        {
            string selectedCache = ncs.SelectedNamedCache;
            if (!string.IsNullOrEmpty(selectedCache))
            {
                CacheHelper.GetNamedCache(selectedCache).Clear();
                AppfabricAdministrator.Current.RefreshForm();
            }
        }


    }
}
